package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.project.entity.IssuePrioritie;

/**
 * 问题优先级Mapper接口
 * 
 * @author ruoyi
 * @date 2025-10-28
 */
@Mapper
public interface IssuePrioritieMapper {

	/**
	 * 查询问题优先级
	 * 
	 * @param id 问题优先级主键
	 * @return 问题优先级
	 */
	@Select("select id, name, position, active, is_default, list_class, html_color, del_flag, create_by, create_time, update_by, update_time from t_issue_priorities where del_flag = 0 and id = #{id}")
	public IssuePrioritie selectIssuePrioritieById(Long id);

	/**
	 * 查询问题优先级列表
	 * 
	 * @param tIssuePriorities 问题优先级
	 * @return 问题优先级集合
	 */
	@Select({"<script>",
		"select id, name, position, active, is_default, list_class, html_color, del_flag, create_by, create_time, update_by, update_time from t_issue_priorities where del_flag = 0 ",
		"  <if test='name != null and name != \"\"'> and name like concat('%', #{name}, '%')</if>",
		"  <if test='position != null'> and position = #{position}</if>",
		"  <if test='active != null'> and active = #{active}</if>",
		"  <if test='isDefault != null'> and is_default = #{isDefault}</if>",
		"  <if test='listClass != null and listClass != \"\"'> and list_class like concat('%', #{listClass}, '%')</if>",
		"  <if test='htmlColor != null and htmlColor != \"\"'> and html_color = #{htmlColor}</if>",
		"  <if test='createTime != null'> and create_time = #{createTime}</if>",
		"  <if test='updateTime != null'> and update_time = #{updateTime}</if>",
		"</script>"
	})
	public List<IssuePrioritie> selectIssuePrioritieList(IssuePrioritie tIssuePriorities);

	/**
	 * 新增问题优先级
	 * 
	 * @param tIssuePriorities 问题优先级
	 * @return 结果
	 */
	@Insert({"<script>",
		"insert into t_issue_priorities",
		"<trim prefix='(' suffix=')' suffixOverrides=','>",
		"  <if test='name != null and name != \"\"'>name,</if>",
		"  <if test='position != null'>position,</if>",
		"  <if test='active != null'>active,</if>",
		"  <if test='isDefault != null'>is_default,</if>",
		"  <if test='listClass != null'>list_class,</if>",
		"  <if test='htmlColor != null and htmlColor != \"\"'>html_color,</if>",
		"  <if test='delFlag != null'>del_flag,</if>",
		"  <if test='createBy != null'>create_by,</if>",
		"  <if test='createTime != null'>create_time,</if>",
		"  <if test='updateBy != null'>update_by,</if>",
		"  <if test='updateTime != null'>update_time,</if>",
		"</trim>",
		"<trim prefix='values (' suffix=')' suffixOverrides=','>",
		"  <if test='name != null and name != \"\"'>#{name},</if>",
		"  <if test='position != null'>#{position},</if>",
		"  <if test='active != null'>#{active},</if>",
		"  <if test='isDefault != null'>#{isDefault},</if>",
		"  <if test='listClass != null'>#{listClass},</if>",
		"  <if test='htmlColor != null and htmlColor != \"\"'>#{htmlColor},</if>",
		"  <if test='delFlag != null'>#{delFlag},</if>",
		"  <if test='createBy != null'>#{createBy},</if>",
		"  <if test='createTime != null'>#{createTime},</if>",
		"</trim>",
		"</script>"
	})
	public int insertIssuePrioritie(IssuePrioritie tIssuePriorities);

	/**
	 * 修改问题优先级
	 * 
	 * @param tIssuePriorities 问题优先级
	 * @return 结果
	 */
	@Update({"<script>",
		"update t_issue_priorities",
		"<trim prefix='SET' suffixOverrides=','>",
		"  <if test='name != null and name != \"\"'>name = #{name},</if>",
		"  <if test='position != null'>position = #{position},</if>",
		"  <if test='active != null'>active = #{active},</if>",
		"  <if test='isDefault != null'>is_default = #{isDefault},</if>",
		"  <if test='listClass != null'>list_class = #{listClass},</if>",
		"  <if test='htmlColor != null and htmlColor != \"\"'>html_color = #{htmlColor},</if>",
		"  <if test='updateBy != null'>update_by = #{updateBy},</if>",
		"  <if test='updateTime != null'>update_time = #{updateTime},</if>",
		"</trim>",
		"where id = #{id}",
		"</script>"
	})
	public int updateIssuePrioritie(IssuePrioritie tIssuePriorities);

	/**
	 * 删除问题优先级
	 * 
	 * @param id 问题优先级主键
	 * @return 结果
	 */
//	@Delete("delete from t_issue_priorities where id = #{id}")
	@Update("update t_issue_priorities set del_flag = 1, update_time = NOW() where id = #{id}")
	public int deleteIssuePrioritieById(Long id);

	/**
	 * 批量删除问题优先级
	 * 
	 * @param ids 需要删除的数据主键集合
	 * @return 结果
	 */
//	@Delete({"<script>",
//		"delete from t_issue_priorities where id in ",
//		"<foreach item='id' collection='array' open='(' separator=',' close=')'>",
//		"  #{id}",
//		"</foreach>",
//		"</script>"
//	})
	@Update("<script>" + "update t_issue_priorities set del_flag = 1, update_time = NOW() where id in "
			+ "<foreach item='id' collection='array' open='(' separator=',' close=')'>" + "#{id}" + "</foreach>"
			+ "</script>")
	public int deleteIssuePrioritieByIds(@Param("array") String[] ids);
	
	@Select("select id, name, position, active, is_default, list_class, html_color, del_flag, create_by, create_time, update_by, update_time from t_issue_priorities where del_flag = 0")
	public List<IssuePrioritie> findAllList();
}
